1 /*
2 ContractChecker
3
4 Copyright (C) 2003 Jose San Leandro Armend?riz
5 jsanleandro@yahoo.es
6 chousz@yahoo.com
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Thanks to ACM S.L. for distributing this library under the GPL license.
23 Contact info: jsanleandro@yahoo.es
24 Postal Address: c/Playa de Lagoa, 1
25 Urb. Valdecaba?as
26 Boadilla del monte
27 28660 Madrid
28 Spain
29
30 ******************************************************************************
31 *
32 * Filename: $RCSfile: ContractCheckerAspectTemplateGenerator.java,v $
33 *
34 * Author: Jose San Leandro Armend?riz
35 *
36 * Description: Is able to generate ContractCheckerAspect templates from
37 * Javadoc information.
38 *
39 * Last modified by: $Author: chous $ at $Date: 2004/01/11 19:44:06 $
40 *
41 * File version: $Revision: 1.4 $
42 *
43 * Project version: $Name: $
44 *
45 * $Id: ContractCheckerAspectTemplateGenerator.java,v 1.4 2004/01/11 19:44:06 chous Exp $
46 *
47 */
48 package org.acmsl.contractchecker;
49
50 /*
51 * Importing some project-specific classes.
52 */
53 import org.acmsl.contractchecker.ContractCheckerAspectTemplate;
54 import org.acmsl.contractchecker.ContractCheckerAspectTemplateFactory;
55 import org.acmsl.contractchecker.ContractCheckerUtils;
56
57 /*
58 * Importing some JDK classes.
59 */
60 import java.io.File;
61 import java.io.IOException;
62 import java.lang.ref.WeakReference;
63
64 /***
65 * Is able to generate ContractCheckerAspect templates from Javadoc
66 * information.
67 * @author <a href="mailto:jsanleandro@yahoo.es"
68 >Jose San Leandro</a>
69 * @version $Revision: 1.4 $
70 * @testcase test.org.acmsl.contractchecker.TestContractCheckerAspectTemplateGenerator
71 */
72 public class ContractCheckerAspectTemplateGenerator
73 implements ContractCheckerAspectTemplateFactory
74 {
75 /***
76 * Singleton implemented as a weak reference.
77 */
78 private static WeakReference singleton;
79
80 /***
81 * Protected constructor to avoid accidental instantiation.
82 */
83 protected ContractCheckerAspectTemplateGenerator() {};
84
85 /***
86 * Specifies a new weak reference.
87 * @param generator the generator instance to use.
88 */
89 protected static void setReference(
90 ContractCheckerAspectTemplateGenerator generator)
91 {
92 singleton = new WeakReference(generator);
93 }
94
95 /***
96 * Retrieves the weak reference.
97 * @return such reference.
98 */
99 protected static WeakReference getReference()
100 {
101 return singleton;
102 }
103
104 /***
105 * Retrieves a ContractCheckerTemplateGenerator instance.
106 * @return such instance.
107 */
108 public static ContractCheckerAspectTemplateGenerator getInstance()
109 {
110 ContractCheckerAspectTemplateGenerator result = null;
111
112 WeakReference reference = getReference();
113
114 if (reference != null)
115 {
116 result = (ContractCheckerAspectTemplateGenerator) reference.get();
117 }
118
119 if (result == null)
120 {
121 result = new ContractCheckerAspectTemplateGenerator() {};
122
123 setReference(result);
124 }
125
126 return result;
127 }
128
129 /***
130 * Generates a ContractChecker template.
131 * @param packageName the package name.
132 * @param defaultException the default exception.
133 * @return a template.
134 */
135 public ContractCheckerAspectTemplate createContractCheckerTemplate(
136 String packageName, String defaultException)
137 {
138 return
139 createContractCheckerAspectTemplate(
140 packageName, defaultException);
141 }
142
143 /***
144 * Generates a ContractCheckerAspect template.
145 * @param packageName the package name.
146 * @param defaultException the default exception.
147 * @return a template.
148 */
149 public ContractCheckerAspectTemplate createContractCheckerAspectTemplate(
150 String packageName, String defaultException)
151 {
152 ContractCheckerAspectTemplate result = null;
153
154 <b>if (packageName != null)
155 {
156 result =
157 new ContractCheckerAspectTemplate(
158 packageName, defaultException) {};
159 }
160
161 return result;
162 }
163
164 /***
165 * Writes a ContractCheckerAspect template to disk.
166 * @param template the template to write.
167 * @param outputDir the output folder.
168 * @throws IOException if the file cannot be created.
169 */
170 public void write(
171 ContractCheckerAspectTemplate template,
172 File outputDir)
173 throws IOException
174 {
175 if ( (template != null)
176 && (outputDir != null))
177 {
178 ContractCheckerUtils t_ContractCheckerUtils =
179 ContractCheckerUtils.getInstance();
180
181 if (t_ContractCheckerUtils != null)
182 {
183 outputDir =
184 t_ContractCheckerUtils.retrieveAspectFolder(
185 outputDir,
186 template.getPackageName());
187
188 outputDir.mkdirs();
189
190 t_ContractCheckerUtils.writeFile(
191 outputDir.getAbsolutePath()
192 + File.separator
193 + "ContractChecking.java",
194 template.toString());
195 }
196 }
197 }
198 }
This page was automatically generated by Maven